/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package email;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
 *
 * @author root
 */
@WebService()
public class EmailWS {

    /**
     * Web service operation
     */
    @WebMethod(operationName = "Email")
    public String Email(@WebParam(name = "To")
    String To, @WebParam(name = "Subject")
    String Subject, @WebParam(name = "Message")
    String Message) {
        this.SaveMessage(To, Subject, Message);
        return "The mail is successfully sent to "+To;
    }

     void SaveMessage(String To, String Subject, String Message)  {
    {
        try {
            FileWriter writer = null;

            String path = "/tmp/SMTP_File";
            writer = new FileWriter(path, true);
            writer.write("Mail sent at "+new Date().toString());
            writer.write("\n To: ");
            writer.write(To, 0, To.length());
            writer.write("\n Subject: ");
            writer.write(Subject, 0, Subject.length());
            writer.write("\n Message: ");
            writer.write(Message, 0, Message.length());
            writer.write("\n");
            writer.write("---------------------- \n");
                if (writer != null) {
                    writer.close();
                }
            } catch (IOException ex)
            {
                Logger.getLogger(EmailWS.class.getName()).log(Level.SEVERE, null, ex);
            }
       }
    }

}
